<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Alarm\Http\Controller\Api;

use App\Http\Admin\Controller\AbstractController as AdminAbstractController;
use App\Http\Common\Middleware\AccessTokenMiddleware;
use App\Http\Common\Result;
use App\Http\CurrentUser;
use http\Env\Request;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\Swagger\Annotation\Get;
use Hyperf\Swagger\Annotation\HyperfServer;
use Mine\Swagger\Attributes\PageResponse;
use Plugin\Alarm\Http\Request\Admin\RdAlarmWarnRecordRequest;
use Plugin\Alarm\Schema\RdAlarmMsgSchema;
use Plugin\Alarm\Schema\RdAlarmWarnRecordSchema;
use Plugin\Alarm\Service\RdAlarmWarnRecordService;

/**
 * 报警记录控制器
 * Class RdAlarmWarnRecordApiController
 */
#[HyperfServer(name: 'http')]
#[Middleware(middleware: AccessTokenMiddleware::class, priority: 100)]
final class RdAlarmWarnRecordApiController extends AdminAbstractController
{

     /**
     * 业务处理服务
     * RdAlarmWarnRecordService
     */
    public function __construct(
        protected readonly RdAlarmWarnRecordService $service,
        protected readonly CurrentUser $currentUser
    ) {}

    #[Get(
        path: '/alarm/rdAlarmWarnRecord/api/list',
        summary: '报警记录列表',
        tags: ['报警记录']
    )]
    #[PageResponse(instance: Result::class)]
    public function index(RdAlarmWarnRecordRequest $request): Result
    {
        return $this->success($this->service->page(array_merge($request->all(), [
            'user_id' => $this->currentUser->id(),
        ])));
    }

    #[Get(
        path: '/alarm/rdAlarmWarnRecord/api/{id}',
        summary: '报警记录详情',
        tags: ['报警记录']
    )]
    #[PageResponse(instance: RdAlarmWarnRecordSchema::class)]
    public function detail(int $id): Result
    {
        return $this->success($this->service->detail($id));
    }
}